﻿/**
 * Store for AllPositions
 */
Ext.define("Cps.store.AllPositions",
{
    extend: "Ext.data.Store",
	
	model: 'Cps.model.AllPosition',
	
	config: {
		params: null,
	},
	
    constructor: function (config)
    {
		if(config)
			this.initConfig(config);
		var grid = Ext.getCmp('gridZone4');
        this.callParent([
        {
            storeId: 'AllPositions',
			groupers: ['PosCategory'],
			data: []
        }]);
    },
	initData: function() {
		var AllPositions = this, f_data = [];
		Ext.Ajax.request({
			method: 'GET',
			url: Cps.Config.Api.getAllPosition,
			params: getParamPosition,
			success: function(data) {
				if (IsJson(data.responseText))
				{
					data = Ext.JSON.decode(data.responseText).data;
					data = data ? data.ttAllPosition : null;
					data = data ? data.ttAllPositionRow : null;
					if (data != undefined)
					{
						if (data.length != undefined)
						{
							for(i = 0; i < data.length; i++) {
								f_data.push(data[i]);
							}
						}
						else
							f_data.push(data);
					}
					AllPositions.loadData(f_data);
					if (Ext.getCmp('mask') != undefined) 
						Ext.getCmp('mask').hide()
				}
			},
			scope: this
		});
	}
});